package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2023-11-27  21:04
 */
public class ThreadDemo17 {
    private static int count = 0;
    public static void main(String[] args) throws InterruptedException {
        Object object = new Object();

        Thread thread = new Thread(() -> {
            for(int i = 0; i < 1_0000; i++) {
                synchronized(object) {
                    count++;
                }
            }
        });

        Thread thread1 = new Thread(() -> {
            for(int i = 0; i < 1_0000; i++) {
                synchronized (object) {
                    count++;
                }
            }
        });
        thread.start();
        thread1.start();

        thread.join();
        thread1.join();

        System.out.println("count = " + count);
    }
}
